//
//  BookCitySearchView.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/5.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "BookCitySearchView.h"

@implementation BookCitySearchView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //竖线
        UIImageView *sepImageView = [[UIImageView alloc]init];
        sepImageView.backgroundColor = CSColorFromRGB(0xF52C50);
        self.sepImageView = sepImageView;
        [self addSubview:sepImageView];
        
        //标题
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"热门搜索";
        titleLable.textColor = CSColorFromRGB(0x6B6763);
        titleLable.font = kFont15;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        //后面按钮
        
        UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [delBtn setImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
        delBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        delBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 10, 10);
        [self addSubview:delBtn];
        self.delBtn = delBtn;
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    //竖线
    [self.sepImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self).offset(15);
        make.centerY.mas_equalTo(self);
        make.width.mas_equalTo(3);
        make.height.mas_equalTo(15);
        
    }];
    
    //标题
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.sepImageView.mas_right).offset(7);
        make.centerY.mas_equalTo(self);
        
        
    }];
    
    //后面按钮
    [self.delBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self).offset(-5);
        make.centerY.mas_equalTo(self);
        
        
    }];
    
}

@end

#pragma mark - 组1cell

@implementation BookCitySearchCellOne

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //排行
        UILabel *rankLable = [[UILabel alloc]init];
        rankLable.text = @"1";
        rankLable.textColor = CSWhiteColor;
        rankLable.backgroundColor = CSColorFromRGB(0xDCDCDC);
        rankLable.font = SmallFont;
        rankLable.textAlignment = NSTextAlignmentCenter;
        rankLable.layer.cornerRadius = 8;
        rankLable.clipsToBounds = YES;
        self.rankLable = rankLable;
        [self addSubview:rankLable];
        
        //标题
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"斗罗大陆斗罗大陆斗罗大陆斗罗大陆斗罗大陆";
        titleLable.textColor = CSBlackColor1;
        titleLable.font = MidFont;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    //排行
    [self.rankLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self).offset(6);
        make.centerY.mas_equalTo(self);
        make.height.width.mas_equalTo(16);
        
    }];
    
    //标题
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.rankLable.mas_right).offset(12);
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-6);
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.width.mas_equalTo(90);
        
    }];
}

@end

#pragma mark - 组2cell

@implementation BookCitySearchCellTwo

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //背景
        UIView *bgView = [[UIView alloc]init];
        bgView.backgroundColor = CSColorFromRGB(0xF5F5F5);
        bgView.layer.cornerRadius = 5;
        bgView.clipsToBounds = YES;
        self.bgView = bgView;
        [self addSubview:bgView];
        
        //搜索按钮
        UIButton *seachBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [seachBtn setImage:[UIImage imageNamed:@"最近搜索搜索灰"] forState:UIControlStateNormal];
        seachBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:seachBtn];
        self.seachBtn = seachBtn;
        
        //标题
        
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"妙手回春";
        titleLable.textColor = CSBlackColor1;
        titleLable.font = MidFont;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        
        [self setConstraints];
        
    }
    return self;
    
}

-(void)setConstraints
{
    //设置约束条件
    
    //背景
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
        
    }];
    
    //搜索按钮
    [self.seachBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self).offset(6);
        make.centerY.mas_equalTo(self);
        make.width.height.mas_equalTo(12);
        
    }];
    
    //标题
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.seachBtn.mas_right).offset(6);
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-6);
        make.width.mas_lessThanOrEqualTo(SCREENWIDTH - 70);
        
    }];
    
}

@end

#pragma mark - 搜索结果

@implementation BookCitySearchCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //封面
        UIImageView *covImageView = [[UIImageView alloc]init];
        covImageView.image = PlaceHold2;
        covImageView.contentMode = UIViewContentModeScaleAspectFill;
        covImageView.clipsToBounds = YES;
        self.covImageView = covImageView;
        [self addSubview:covImageView];
        
        //书名
        UILabel *titleLable = [[UILabel alloc]init];
        titleLable.text = @"极品女上";
        titleLable.textColor = CSBlackColor1;
        titleLable.font = SmallFont;
        self.titleLable = titleLable;
        [self addSubview:titleLable];
        
        //内容
        UILabel *contenLable = [[UILabel alloc]init];
        contenLable.text = @"书籍简介书籍简介书籍简介书籍简介书籍简介书籍简介书籍简介书书籍简介书籍简介书籍简介...";
        contenLable.numberOfLines = 2;
        contenLable.textColor = CSColorFromRGB(0x6B6763);
        contenLable.font = SmallFont;
        self.contenLable = contenLable;
        [self addSubview:contenLable];
        
        //作者
        UIImageView *nameImageView = [[UIImageView alloc]init];
        nameImageView.image = [UIImage imageNamed:@"个人灰色"];
        nameImageView.contentMode = UIViewContentModeScaleAspectFill;
        nameImageView.clipsToBounds = YES;
        self.nameImageView = nameImageView;
        [self addSubview:nameImageView];
        
        UILabel *nameLable = [[UILabel alloc]init];
        nameLable.text = @"糖加三勺";
        nameLable.textColor = CSColorFromRGB(0x6B6763);
        nameLable.font = SmallFont;
        self.nameLable = nameLable;
        [self addSubview:nameLable];
        
        
        
        //类型
        
        UIButton *typeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [typeBtn setTitle:@"都市小说" forState:UIControlStateNormal];
        [typeBtn setTitleColor:CSColorFromRGB(0x3297EC) forState:UIControlStateNormal];
        typeBtn.titleLabel.font = [UIFont systemFontOfSize:9];
        typeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        typeBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        typeBtn.imageView.layer.masksToBounds = YES;
        typeBtn.layer.borderColor = CSColorFromRGB(0x3297EC).CGColor;
        typeBtn.layer.borderWidth = 1;
        typeBtn.layer.cornerRadius = 2;
        typeBtn.clipsToBounds = YES;
        typeBtn.contentEdgeInsets = UIEdgeInsetsMake(4, 4, 4, 4);
        [self addSubview:typeBtn];
        self.typeBtn = typeBtn;
        
        //状态
        UIButton *stateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [stateBtn setTitle:@"连载中" forState:UIControlStateNormal];
        [stateBtn setTitleColor:CSColorFromRGB(0x3297EC) forState:UIControlStateNormal];
        stateBtn.titleLabel.font = [UIFont systemFontOfSize:9];
        stateBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        stateBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        stateBtn.imageView.layer.masksToBounds = YES;
        stateBtn.layer.borderColor = CSColorFromRGB(0x3297EC).CGColor;
        stateBtn.layer.borderWidth = 1;
        stateBtn.layer.cornerRadius = 2;
        stateBtn.clipsToBounds = YES;
        stateBtn.contentEdgeInsets = UIEdgeInsetsMake(4, 4, 4, 4);
        [self addSubview:stateBtn];
        self.stateBtn = stateBtn;
        
        //字数
        UIButton *numberBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [numberBtn setTitle:@"1000万字" forState:UIControlStateNormal];
        [numberBtn setTitleColor:CSColorFromRGB(0x3297EC) forState:UIControlStateNormal];
        numberBtn.titleLabel.font = [UIFont systemFontOfSize:9];
        numberBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        numberBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        numberBtn.imageView.layer.masksToBounds = YES;
        numberBtn.layer.borderColor = CSColorFromRGB(0x3297EC).CGColor;
        numberBtn.layer.borderWidth = 1;
        numberBtn.layer.cornerRadius = 2;
        numberBtn.clipsToBounds = YES;
        numberBtn.contentEdgeInsets = UIEdgeInsetsMake(4, 4, 4, 4);
        [self addSubview:numberBtn];
        self.numberBtn = numberBtn;
        
        [self setConstraints];
        
    }
    return self;
}

-(void)setConstraints
{
    //设置约束条件
    
    [self.covImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self).offset(10);
        make.left.mas_equalTo(self).offset(12);
        make.bottom.mas_equalTo(self).offset(-10);
        make.width.mas_equalTo(SCREENWIDTH/375 *72);
        make.height.mas_equalTo(SCREENWIDTH/375 *96);
        
    }];
    
    //书名
    [self.titleLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.covImageView).offset(0);
        make.left.mas_equalTo(self.covImageView.mas_right).offset(12);
        make.right.mas_lessThanOrEqualTo(self).offset(-15);
        
    }];
    
    //内容
    [self.contenLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLable.mas_bottom).offset(10);
        make.left.mas_equalTo(self.titleLable);
        make.right.mas_equalTo(self).offset(-15);
        
    }];
    
    //作者
    [self.nameImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.nameLable);
        make.left.mas_equalTo(self.titleLable);
        
    }];
    
    [self.nameLable mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.covImageView).offset(-0);
        make.left.mas_equalTo(self.nameImageView.mas_right).offset(5);
        make.right.mas_lessThanOrEqualTo(self.typeBtn.mas_left).offset(-10);
        
    }];
    
    //类型
    [self.typeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.nameLable);
        make.right.mas_equalTo(self.stateBtn.mas_left).offset(-5);
        
    }];
    
    //状态
    [self.stateBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.nameLable);
        make.right.mas_equalTo(self.numberBtn.mas_left).offset(-5);
        
    }];
    
    //字数
    [self.numberBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.nameLable);
        make.right.mas_equalTo(self.contenLable);
        
    }];
}

-(void)layoutSubviews
{
}

@end
